package com.epalmpay.service.ys.indexService.impl;

import com.epalmpay.dto.mall.MallGoodOutDTO;
import com.epalmpay.dto.merchant.index.StatisGroupDayOutDTO;
import com.epalmpay.dto.prepurchase.PrePurActivityStaticOutDTO;
import com.epalmpay.dto.yunliu.index.agent.YsAgentIndexInDTO;
import com.epalmpay.dto.yunliu.index.agent.YsAgentIndexOutDTO;
import com.epalmpay.dto.yunliu.index.merchant.PreActivityOutDTO;
import com.epalmpay.dto.yunliu.index.merchant.YsGroupIndexInDTO;
import com.epalmpay.entity.*;
import com.epalmpay.entity.profit.Profit;
import com.epalmpay.mapper.*;
import com.epalmpay.service.ys.indexService.IYsIndexService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
 * Created by Administrator on 2017/9/7.
 */

@Service("ysIndexService")
public class YsIndesServiceImpl implements IYsIndexService{

    @Resource
    private StatisGroupDayMapper statisGroupDayMapper;

    @Resource
    private StatisGroupMapper statisGroupMapper;

    @Resource
    private MallGoodMapper  mallGoodMapper;

    @Resource
    private StatisAgentDayMapper statisAgentDayMapper;

    @Resource
    private StatisAgentMapper statisAgentMapper;

    @Resource
    private StatisShopMapper statisShopMapper;

    @Resource
    private PrePurchaseActivityMapper prePurchaseActivityMapper;

    @Resource
    private YsObdMapper ysObdMapper;

    @Resource
    private OrderGoodMapper orderGoodMapper;

    @Resource
    private AgentMapper agentMapper;
    @Resource
    private TradeOfflineMapper tradeOfflineMapper;

    @Resource
    private ProfitMapper profitMapper;

    @Resource
    private PrepurchaseActivityStatisMapper prepurchaseActivityStatisMapper;

    @Resource
    private MemberMapper memberMapper;

    @Resource
    private ShopMapper shopMapper;




    /**
     * 渠道后台
     * @param groupIndexInDTO
     * @return
     */
    @Override
    public StatisGroupDay queryTodayAddMemberCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setTodayStatisDate(new Date());
        return statisGroupDayMapper.queryTodayAddMemberCount(groupIndexInDTO);
         //今日相关的只能实时查询
        //查询今日新增会员数 今日商城订单数.今日线下收银金额 今日商城订单金额 .今日交易预估收益 .今日预采购预估收益
    }
//
//    @Override
//    public StatisGroupDay queryYestTodayAddMemberCount(YsGroupIndexInDTO groupIndexInDTO) {
//        Date date = new Date();
//        Calendar calendar = new GregorianCalendar();
//        calendar.setTime(date);
//        calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
//        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
//        groupIndexInDTO.setStatisDate(date);//昨日
//        return statisGroupDayMapper.queryYestTodayAddMemberCount(groupIndexInDTO);
//    }

    @Override
    public PrePurchaseActivity queryPrepurchaseActivityCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return prePurchaseActivityMapper.queryPrepurchaseActivityCount(groupIndexInDTO);
    }

    @Override
    public YsObd queryObdCount(YsGroupIndexInDTO groupIndexInDTO) throws Exception {
        groupIndexInDTO.setStatisDate(new Date());
        return ysObdMapper.queryObdCount(groupIndexInDTO);
    }

    @Override
    public YsObd queryObddistributionCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return ysObdMapper.queryObddistributionCount(groupIndexInDTO);
    }

    @Override
    public OrderGood queryOrderGoodCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return orderGoodMapper.queryOrderGoodCount(groupIndexInDTO);
    }

    @Override
    public Agent queryPreAmount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return agentMapper.queryPreAmount(groupIndexInDTO);
    }

    @Override
    public TradeOffline queryDayTradeAmount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return tradeOfflineMapper.queryDayTradeAmount(groupIndexInDTO);
    }

    @Override
    public Profit queryDayProfitAmount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return profitMapper.queryDayProfitAmount(groupIndexInDTO);
    }

    @Override
    public Profit queryDayPreProfitAmount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return profitMapper.queryDayPreProfitAmount(groupIndexInDTO);
    }

    @Override
    public PrepurchaseActivityStatis queryDayPrepurchaseAmount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return prepurchaseActivityStatisMapper.queryDayPrepurchaseAmount(groupIndexInDTO);
    }

    @Override
    public List<PreActivityOutDTO> queryPurActivity(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return prePurchaseActivityMapper.queryPurActivity(groupIndexInDTO);
    }

    @Override
    public Member queryAddTodayMemberCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return memberMapper.queryAddTodayMemberCount(groupIndexInDTO);
    }

    @Override
    public Member queryAddYestMemberCount(YsGroupIndexInDTO groupIndexInDTO) {
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
        groupIndexInDTO.setStatisDate(date);//昨日
        return memberMapper.queryAddTodayMemberCount(groupIndexInDTO);
    }

    @Override
    public Shop queryAddShopCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return shopMapper.queryAddShopCount(groupIndexInDTO);
    }

    @Override
    public Agent queryAddAgentCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return agentMapper.queryAddAgentCount(groupIndexInDTO);
    }

//    @Override
//    public StatisGroup queryStatisGroupData(YsGroupIndexInDTO groupIndexInDTO) {
//        groupIndexInDTO.setStatisDate(new Date());
//        return statisGroupMapper.queryStatisGroupData(groupIndexInDTO);
//    }

    @Override
    public List<MallGoodOutDTO> queryMallGoodCount(YsGroupIndexInDTO groupIndexInDTO) {
        groupIndexInDTO.setStatisDate(new Date());
        return mallGoodMapper.queryMallGoodCount(groupIndexInDTO);
    }

    @Override
    public List<StatisGroupDayOutDTO> queryYsSevenDayData(YsGroupIndexInDTO groupIndexInDTO) {
        return statisGroupDayMapper.queryYsSevenDayData(groupIndexInDTO);
    }

    /**
     * 代理商首页
     */

    @Override
    public StatisAgentDay queryAgentTodayAddMemberCount(YsAgentIndexInDTO agentIndexInDTO) throws Exception {
        agentIndexInDTO.setTodayStatisDate(new Date());
        return statisAgentDayMapper.queryAgentTodayAddMemberCount(agentIndexInDTO);
    }

    @Override
    public StatisAgentDay queryYsAgentYestAddMemberCount(YsAgentIndexInDTO agentIndexInDTO) {
        return statisAgentDayMapper.queryYsAgentYestAddMemberCount(agentIndexInDTO);
    }

    @Override
    public StatisAgent queryYsStatisAgentData(YsAgentIndexInDTO agentIndexInDTO) {
        return statisAgentMapper.queryYsStatisAgentData(agentIndexInDTO);
    }

    @Override
    public List<YsAgentIndexOutDTO> queryAgentFiveData(YsAgentIndexInDTO agentIndexInDTO) {

        return statisShopMapper.queryAgentFiveData(agentIndexInDTO);
    }




}
